<?php
    // Tests the existence of a table in the database.
    // Parameters : tableName[string], db[object(PDO)]
    // Return : boolean
    function tableExists($tableName, $db)
    {
        // Creating the query.
        $query =
        'SHOW TABLES LIKE ?';
        
        // Preparing and executing the query.
        $queryResult = $db->prepare($query);
        $queryResult->execute(array($tableName));
        
        // Storing the result
        $isTableExisting = (is_array($queryResult->fetch()) ? true : false);
        
        // Returning the boolean.
        return $isTableExisting;
    }
    
    // Shows the required table.
    // Parameters : tableName[string], db[object(PDO)]
    // Return : array[array[string]]
    function getTableInfos($tableName, $db)
    {
        // Creating the queries.
        $queryColumns =
        'DESCRIBE m2l.' . $tableName;
        $queryValues =
        'SELECT * FROM ' . $tableName;
        $tableColumnsNames = array();
        $tableValues = array();
        
        // Preparing and executing the queries.
        $queryColumnsResult = $db->query($queryColumns);
        foreach ($queryColumnsResult as $resultLine)
        {
            $tableColumnsNames[] = $resultLine['Field'];
        }
        $queryColumnsResult->closeCursor();
        
        $queryValuesResult = $db->query($queryValues);
        foreach ($queryValuesResult as $resultLine)
        {
            $tableValues[] = $resultLine;
        }
        
        return array($tableColumnsNames, $tableValues);
    }
?>
